package com.srs.backend.controller;

import com.srs.backend.consumer.WebSocketServer;
import com.srs.backend.pojo.User;
import com.srs.backend.service.UserService;
import com.srs.backend.utils.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/user")
public class UserController {
    @Resource
    private UserService userService;

    @PostMapping("/login/")
    public Result login(@RequestBody Map<String, String> data) {
        return userService.login(data);
    }

    @PostMapping("/register/")
    public Result register(@RequestBody Map<String, String> data) {
        return userService.register(data);
    }

    @PostMapping("/add/")
    public Result add(@RequestBody Map<String, String > data) {
        return userService.addUser(data);
    }

    @PostMapping("/delete/")
    public Result delete(@RequestBody Map<String, String > data) {
        return userService.deleteUser(data);
    }

    @PostMapping("/update/")
    public Result update(@RequestBody Map<String, String > data) {
        return userService.updateUser(data);
    }

    @PostMapping("/get/all/")
    public Result getAll(@RequestBody Map<String, String> data) {
        return userService.getAll();
    }

    @PostMapping("/get/current/user/info/")
    public Result getCurUserInfo() {
        return userService.getCurUserInfo();
    }

    @PostMapping("/test/")
    public void websocketTest() throws IOException {
        WebSocketServer.sendInfo(12, Result.ok("ok"));
    }
}
